<html>
<head><meta charset="utf-8"><title>Adding mut/owning semantic modifiers for fns · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html">Adding mut/owning semantic modifiers for fns</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205482617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205482617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205482617">(Jul 30 2020 at 14:08)</a>:</h4>
<p>Hi <span class="user-mention" data-user-id="133169">@matklad</span> , what are your thoughts on adding mutable and owning (Maybe a different name, but would be a new <code>HighlightModifier</code>) semantic modifiers to fns that take <code>&amp;mut self</code> and <code>self</code>, respectively? I remember when I was doing rust years ago, as a beginner, I found it hard to understand how certain method calls were changing the behavior of the borrow checker. I don't propose any default syntax highlighting yet, but thought it might be useful to experiment with.</p>



<a name="205482681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205482681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205482681">(Jul 30 2020 at 14:09)</a>:</h4>
<p>We already have <code>mutable</code></p>



<a name="205482793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205482793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205482793">(Jul 30 2020 at 14:10)</a>:</h4>
<p>I meant new only for the <code>owning</code> one.</p>



<a name="205482821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205482821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205482821">(Jul 30 2020 at 14:10)</a>:</h4>
<p>I think highlighitng functions calls that are actually mutable might be a good idea</p>



<a name="205482844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205482844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205482844">(Jul 30 2020 at 14:10)</a>:</h4>
<p>I wanted to distinguish between &amp;, &amp;mut and moving fns</p>



<a name="205482863"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205482863" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205482863">(Jul 30 2020 at 14:10)</a>:</h4>
<p>(there's more general idea of highlighing not mutable types, but rather mutation points)</p>



<a name="205482922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205482922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205482922">(Jul 30 2020 at 14:11)</a>:</h4>
<p>I think marking consumed non-Copy things might also be a good idea</p>



<a name="205482971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205482971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205482971">(Jul 30 2020 at 14:11)</a>:</h4>
<p>/s we can use <del>strikethrough</del>, because the thing is GONE :D</p>



<a name="205483015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205483015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205483015">(Jul 30 2020 at 14:11)</a>:</h4>
<p>XD</p>



<a name="205483176"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205483176" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205483176">(Jul 30 2020 at 14:13)</a>:</h4>
<p>Back when I had the borrow visualizer prototype working, it was a red outline around the moved value.</p>



<a name="205483224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205483224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205483224">(Jul 30 2020 at 14:13)</a>:</h4>
<p>I'll play around and see what looks nice and not horribly distracting</p>



<a name="205592500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205592500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205592500">(Jul 31 2020 at 13:56)</a>:</h4>
<p>So I've been stuck on the <code>Copy</code> part of this for a while now. I (think) I have the logic down where once I have the <code>Copy</code> trait, I can validate whether the type impls <code>Copy</code> or not. However I'm stuck actually finding the <code>Copy</code> trait. My current attempt was to move <code>FamousDefs</code> from <code>ra_assists::utils</code> to a new module <code>ra_hir::utils</code>, and add a <code>core_marker_Copy</code> fn that looks for <code>core:marker:Copy</code> (very similar to the <code>From</code> and <code>Option</code> fns). However, this always fails to find <code>core</code> (and even <code>std</code>). Any thoughts on what I could do to fix this or maybe a better way to figure out whether a type is <code>Copy</code> or not?</p>



<a name="205595148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205595148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205595148">(Jul 31 2020 at 14:16)</a>:</h4>
<p>somewhere where you have a db,</p>
<div class="codehilite"><pre><span></span><code><span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">trait_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="n">db</span><span class="p">.</span><span class="n">lang_item</span><span class="p">(</span><span class="n">krate</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;copy&quot;</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="nb">Some</span><span class="p">(</span><span class="n">LangItemTarget</span>::<span class="n">TraitId</span><span class="p">(</span><span class="n">trait_</span><span class="p">))</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">trait_</span><span class="p">),</span><span class="w"></span>
<span class="w">            </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="nb">None</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="p">};</span><span class="w"></span>
</code></pre></div>



<a name="205595178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205595178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205595178">(Jul 31 2020 at 14:16)</a>:</h4>
<p>that's the way to get lang items</p>



<a name="205612082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205612082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205612082">(Jul 31 2020 at 16:33)</a>:</h4>
<p>Well that's so much easier than what I was trying to do <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span>. I'll give that a try after work. Thanks!</p>



<a name="205685035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205685035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205685035">(Aug 01 2020 at 15:00)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span> so this doesn't seem to be working for me:</p>
<div class="codehilite"><pre><span></span><code><span class="w">            </span><span class="kd">let</span><span class="w"> </span><span class="n">krate</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Function</span>::<span class="n">from</span><span class="p">(</span><span class="n">func</span><span class="p">).</span><span class="n">krate</span><span class="p">(</span><span class="bp">self</span><span class="p">.</span><span class="n">db</span><span class="p">)</span><span class="o">?</span><span class="p">;</span><span class="w"></span>
<span class="w">            </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;Crate is {:?}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">krate</span><span class="p">);</span><span class="w"></span>
<span class="w">            </span><span class="kd">let</span><span class="w"> </span><span class="n">lang_item</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">db</span><span class="p">.</span><span class="n">lang_item</span><span class="p">(</span><span class="n">krate</span><span class="p">.</span><span class="n">id</span><span class="p">,</span><span class="w"> </span><span class="n">SmolStr</span>::<span class="n">new</span><span class="p">(</span><span class="s">&quot;copy&quot;</span><span class="p">));</span><span class="w"></span>
<span class="w">            </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;copy lang_item? {:?}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">lang_item</span><span class="p">);</span><span class="w"></span>
</code></pre></div>


<p>The above code prints these logs (where self is <code>SemanticsImpl</code>)</p>
<div class="codehilite"><pre><span></span><code>Crate is Crate { id: CrateId(0) }
copy lang_item? None
</code></pre></div>



<a name="205685062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205685062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205685062">(Aug 01 2020 at 15:02)</a>:</h4>
<p>If that's in a unit test, keep in mind that you don't have the standard library and actually have to define it</p>



<a name="205685161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205685161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205685161">(Aug 01 2020 at 15:04)</a>:</h4>
<p>I was JUST about to ask that</p>



<a name="205685313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205685313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205685313">(Aug 01 2020 at 15:08)</a>:</h4>
<p>Ok, that's working now. Thanks!</p>



<a name="205685887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205685887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205685887">(Aug 01 2020 at 15:24)</a>:</h4>
<p>So I got stuck on <code>impl Copy for MyType {}</code> vs <code>#[derive(Copy, Clone)] struct MyType ...</code>. Is the latter supposed to be recognized as a trait impl within a unit test?</p>



<a name="205685947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205685947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205685947">(Aug 01 2020 at 15:26)</a>:</h4>
<p>What I'm doing is:</p>
<div class="codehilite"><pre><span></span><code><span class="w">            </span><span class="kd">let</span><span class="w"> </span><span class="n">ty</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">type_of_self</span><span class="p">(</span><span class="o">&amp;</span><span class="n">self_param</span><span class="p">)</span><span class="o">?</span><span class="p">;</span><span class="w"></span>
<span class="w">            </span><span class="kd">let</span><span class="w"> </span><span class="n">krate</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Function</span>::<span class="n">from</span><span class="p">(</span><span class="n">func</span><span class="p">).</span><span class="n">krate</span><span class="p">(</span><span class="bp">self</span><span class="p">.</span><span class="n">db</span><span class="p">)</span><span class="o">?</span><span class="p">;</span><span class="w"></span>
<span class="w">            </span><span class="kd">let</span><span class="w"> </span><span class="n">lang_item</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">db</span><span class="p">.</span><span class="n">lang_item</span><span class="p">(</span><span class="n">krate</span><span class="p">.</span><span class="n">id</span><span class="p">,</span><span class="w"> </span><span class="n">SmolStr</span>::<span class="n">new</span><span class="p">(</span><span class="s">&quot;copy&quot;</span><span class="p">));</span><span class="w"></span>
<span class="w">            </span><span class="kd">let</span><span class="w"> </span><span class="n">copy_trait</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="n">lang_item</span><span class="o">?</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="n">LangItemTarget</span>::<span class="n">TraitId</span><span class="p">(</span><span class="n">copy_trait</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">Trait</span>::<span class="n">from</span><span class="p">(</span><span class="n">copy_trait</span><span class="p">),</span><span class="w"></span>
<span class="w">                </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nb">None</span><span class="p">,</span><span class="w"></span>
<span class="w">            </span><span class="p">};</span><span class="w"></span>
<span class="w">            </span><span class="k">if</span><span class="w"> </span><span class="n">ty</span><span class="p">.</span><span class="n">impls_trait</span><span class="p">(</span><span class="bp">self</span><span class="p">.</span><span class="n">db</span><span class="p">,</span><span class="w"> </span><span class="n">copy_trait</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="p">[])</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="o">..</span><span class="p">.</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>The <code>if</code> block is entered only when I have <code>impl Copy for MyType {}</code>, and not with the derive syntax. Is this just a peculiarity with the test, or would this actually be an issue on real code?</p>



<a name="205687732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205687732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205687732">(Aug 01 2020 at 16:16)</a>:</h4>
<p>you would need to define the built-in macro for the latter to be resolved</p>



<a name="205687745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205687745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205687745">(Aug 01 2020 at 16:17)</a>:</h4>
<p>I'd just use <code>impl Copy for MyType {}</code></p>



<a name="205687814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205687814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205687814">(Aug 01 2020 at 16:18)</a>:</h4>
<p>i.e. you need <a href="https://github.com/rust-lang/rust/blob/cfdf9d335501cc0a53ae69c940095cca7d4be0f8/library/core/src/marker.rs#L375-L381">this boilerplate</a> so the derive can be resolved</p>



<a name="205687842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205687842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205687842">(Aug 01 2020 at 16:19)</a>:</h4>
<p>... I think? <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> actually maybe the problem is rather that the derive expects the <code>Copy</code> trait to be at the path that it usually is</p>



<a name="205689060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205689060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205689060">(Aug 01 2020 at 16:51)</a>:</h4>
<p>Just got back to my desk. None of that worked... I think I'll just use the <code>impl Copy ...</code> for the test to keep it simple. Thanks so much for your help today!</p>



<a name="205689223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205689223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205689223">(Aug 01 2020 at 16:54)</a>:</h4>
<p>I.e. I tried</p>
<div class="codehilite"><pre><span></span><code><span class="k">mod</span> <span class="nn">core</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">mod</span> <span class="nn">marker</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="cp">#[lang = </span><span class="s">&quot;copy&quot;</span><span class="cp">]</span><span class="w"></span>
<span class="w">        </span><span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="nb">Copy</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="w">        </span><span class="cp">#[rustc_builtin_macro]</span><span class="w"></span>
<span class="w">        </span><span class="cp">#[allow_internal_unstable(core_intrinsics, derive_clone_copy)]</span><span class="w"></span>
<span class="w">        </span><span class="k">pub</span><span class="w"> </span><span class="kr">macro</span><span class="w"> </span><span class="nb">Copy</span><span class="p">(</span><span class="cp">$item</span>:<span class="nc">item</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>And the derive still wasn't recognized as an <code>impl Trait</code>. I tried with the clone bounds as well and that didn't make a difference.</p>



<a name="205689855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205689855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205689855">(Aug 01 2020 at 17:11)</a>:</h4>
<p>Turns out this is all that's needed:</p>
<div class="codehilite"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">mod</span> <span class="nn">marker</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="cp">#[lang = </span><span class="s">&quot;copy&quot;</span><span class="cp">]</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="nb">Copy</span><span class="w">  </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>If there is no core dep, then the <code>krate</code> for the lang item is assumed to be just the <code>crate</code> keyword.</p>



<a name="205691681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205691681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205691681">(Aug 01 2020 at 17:57)</a>:</h4>
<p>PR up here: <a href="https://github.com/rust-analyzer/rust-analyzer/pull/5643">https://github.com/rust-analyzer/rust-analyzer/pull/5643</a></p>



<a name="205859595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205859595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205859595">(Aug 03 2020 at 23:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116114">Paul Faria</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns/near/205483224">said</a>:</p>
<blockquote>
<p>I'll play around and see what looks nice and not horribly distracting</p>
</blockquote>
<p>I'd just ask to make it a modifier, and then theme it separately, vs. pushing textmate formatted scopes to the IDE(s).  We'll need to work to get these taken advantage of in various themes (and samples for devs to add on their own, like the examples that I have put up), but I think it's a better path forward than trying to make formatting decisions in RA itself.</p>



<a name="205902792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Adding%20mut/owning%20semantic%20modifiers%20for%20fns/near/205902792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Adding.20mut.2Fowning.20semantic.20modifiers.20for.20fns.html#205902792">(Aug 04 2020 at 13:00)</a>:</h4>
<p>That's the path I ended up on in the PR. The <code>function.mutable</code>s  get an underline since the <code>mutable</code> modifier adds an underline by default. I didn't add any styling to <code>consuming</code> (I feel like I should use a more typical rust name here like owning or moving/moved, brought up the same in the PR).</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>